package com.example.administrator.recyclerviewtestdata_302hrx.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import com.example.administrator.recyclerviewtestdata_302hrx.R;
import com.example.administrator.recyclerviewtestdata_302hrx.adapter.MyAdapterTcase;
import com.example.administrator.recyclerviewtestdata_302hrx.bean.TcaseBean;
import com.example.administrator.recyclerviewtestdata_302hrx.iface.TcaseListener;
import com.example.administrator.recyclerviewtestdata_302hrx.model.TcaseModel;

import java.util.List;

public class MainActivity extends AppCompatActivity {
    private RecyclerView recyclerView;
    private RecyclerView.LayoutManager layoutManager;
   // private MyAdapter mAdapter;
    private MyAdapterTcase myAdapterTcase;
    private List<TcaseBean> list = null;

    private TcaseListener articleListener = new TcaseListener() {
        @Override
        public void onResponse(List<TcaseBean> tcaseBeen) {
            list = tcaseBeen;
           // mAdapter.setList(list);
            myAdapterTcase.setList(list);
            //数据更新的话
           // mAdapter.notifyDataSetChanged();
            myAdapterTcase.notifyDataSetChanged();
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(MainActivity.this,msg,Toast.LENGTH_SHORT);
        }
    };

    private void initRecyclerView() {
        recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
        //创建默认的线性LayoutManager
        layoutManager = new LinearLayoutManager(this);
        //设置布局管理器
        recyclerView.setLayoutManager(layoutManager);
        //如果可以确定每个item的高度是固定的，设置这个选项可以提高性能
        recyclerView.setHasFixedSize(true);
        //创建并设置Adapter
       // list = getData();
//        mAdapter = new MyAdapter(this);
//        mAdapter.setList(list);
//        recyclerView.setAdapter(mAdapter);
        myAdapterTcase = new MyAdapterTcase(this);
        myAdapterTcase.setList(list);
        recyclerView.setAdapter(myAdapterTcase);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_tcase);
        initRecyclerView();
        //实例化model 然后调用方法  获取网络数据
        //4实例化
       // ArticleModel articleModel = new ArticleModel();
        TcaseModel tcaseModel = new TcaseModel();
        //articleModel.getResultList("tcase",2,"rv1l2tidbomann2qn86nln6ur2",articleListener);
        tcaseModel.getResultList("tware",2,"rv1l2tidbomann2qn86nln6ur2",articleListener);
    }


    /*
    private List<ArticleBean> getData() {
        List<ArticleBean> list = new ArrayList<ArticleBean>();
        for (int i = 1; i <= 20; i++) {
            ArticleBean art;
            art = new ArticleBean();
            art.setArticleId(i);
            art.setTitle("标题"+i);
            art.setImgid(R.drawable.f2);
            art.setTime("2017-4-1 15:16");
            art.setDescription("描述"+i);
            list.add(art);
        }

        return list;
    }
*/
}
